//
//  TAMTHomeTopCell.swift
//  TAMeetApp
//
//  Created by Admin on 2024/12/1.
//

import UIKit
import SDWebImage

@objc protocol TAMTHomeTopCellDelegate: NSObjectProtocol {
    func didOnMoreAction()
}

class TAMTHomeTopCell: UICollectionViewCell {
    
    @objc weak var delegate :TAMTHomeTopCellDelegate?
    
    //top横幅
    lazy var platypusView = {
        let blueberry = UIView()
        blueberry.backgroundColor = UIColor(red: 1, green: 1, blue: 1, alpha: 0.6)
        return blueberry
    }()

    //头像
    lazy var alligatorImageView = {
        let kiwano = UIImageView()
        kiwano.contentMode = .scaleAspectFill
        kiwano.clipsToBounds = true

        kiwano.layer.cornerRadius = 16;
        kiwano.layer.masksToBounds = true;
        return kiwano
    }()

    //昵称
    lazy var octopusLabel = {
        let platypus = UILabel()
        platypus.textColor = UIColor(red: 255/255.0, green: 255/255.0, blue: 255/255.0, alpha: 1.0)
        platypus.font = UIFont.systemFont(ofSize: 14, weight: .medium);

        return platypus
    }()

    //性别
    lazy var pigeonImageView = {
        let race = UIImageView()

        return race
    }()

    //城市
    lazy var redfoxLabel = {
        let soak = UILabel()
        soak.textColor = UIColor(red: 255.0/255.0, green: 255.0/255.0, blue: 255.0/255.0, alpha: 1.0)
        soak.font = UIFont.systemFont(ofSize: 12);

        return soak
    }()

//    //点赞数量
//    lazy var blackpantherLabel = {
//        let arrange = UILabel()
//        arrange.text = "0"
//        arrange.textColor = UIColor(red: 255.0/255.0, green: 255.0/255.0, blue: 255.0/255.0, alpha: 1.0)
//        arrange.numberOfLines = 0
//        arrange.font = UIFont.systemFont(ofSize: 11);
//
//        return arrange
//    }()
//
//    //点赞按钮
//    lazy var seahorseButton = {
//        let dove = UIButton(type: .custom)
//        dove.addTarget(self, action: #selector(galaappleOnLikeactionAction), for: .touchUpInside)
//        dove.setImage(UIImage(named: "like_n"), for: .normal)
//        dove.setImage(UIImage(named: "like_s"), for: .selected)
//        return dove
//    }()
//
//    //分割线
//    lazy var dragonflyView = {
//        let greenapple = UIView()
//        greenapple.backgroundColor = .white
//        return greenapple
//    }()

    //回复按钮
    lazy var sheepButton = {
        let cantaloupe = UIButton(type: .custom)
        cantaloupe.setTitle("回复", for: .normal)
        cantaloupe.setTitleColor(UIColor(red: 255.0/255.0, green: 255.0/255.0, blue: 255.0/255.0, alpha: 1.0), for: .normal)
        cantaloupe.setImage(UIImage(named: "replay"), for: .normal)
        cantaloupe.addTarget(self, action: #selector(starfruitOnReplayactionAction), for: .touchUpInside)
        cantaloupe.titleEdgeInsets = UIEdgeInsets(top: 0, left: 4, bottom: 0, right: 0)
        cantaloupe.titleLabel?.font = UIFont.systemFont(ofSize: 11, weight: .medium);

        return cantaloupe
    }()

    //更多按钮
    lazy var impalaButton = {
        let grasshopper = UIButton(type: .custom)
        grasshopper.setBackgroundImage(UIImage(named: "home_more"), for: .normal)
        grasshopper.addTarget(self, action: #selector(dragonfruitOnMoreactionAction), for: .touchUpInside)
        return grasshopper
    }()

    //文本内容
    lazy var piranhaLabel = {
        let mosquito = UILabel()
        mosquito.textColor = UIColor(red: 255.0/255.0, green: 255.0/255.0, blue: 255.0/255.0, alpha: 1.0)
        mosquito.numberOfLines = 0
        mosquito.font = UIFont.systemFont(ofSize: 14);
        mosquito.textAlignment = .center

        return mosquito
    }()

    
    lazy var myView:UIImageView = {
        let admin = UIImageView()
        admin.image = UIImage(named: "bgtop")
        admin.layer.cornerRadius = 10
        admin.layer.masksToBounds = true
        admin.isUserInteractionEnabled = true
        admin.contentMode  = .scaleAspectFill
        admin.clipsToBounds = true
        return admin
    }()
    
    @objc var model:TAMTHomeTopBsShowingList!  {
        didSet {
            alligatorImageView.sd_setImage(with: NSURL(string: model.miaImageRose) as URL?, placeholderImage: placeImage)
            octopusLabel.text = model.ellaNickNameBella!
            
            if model.noahSexScarlett == 0 {
                pigeonImageView.image = UIImage(named: "sex_nan")
            }
            else {
                pigeonImageView.image = UIImage(named: "sex_nv")
            }
            redfoxLabel.text = String(format: "IP属地：%@", model.ethanLocationRuby)
            
            piranhaLabel.attributedText = model.benTextDaisy.attributedStringWithlineSpacing(5, textColor: UIColor.white, font: UIFont.systemFont(ofSize: 15, weight: .medium))
        }
    }
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        
        contentView.backgroundColor = .clear;
        self.backgroundColor = .clear
        
        self.contentView.addSubview(myView)
        myView.snp.makeConstraints { make in
            make.leading.equalTo(16)
            make.trailing.equalTo(-16)
            make.top.bottom.equalToSuperview()
        }
        
        allInitViews()
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    private func allInitViews() {

        myView.addSubview(platypusView)
        platypusView.snp.makeConstraints { make in
            make.height.equalTo(50);
            make.top.equalTo(myView);
            make.leading.equalTo(myView);
            make.trailing.equalTo(myView);
        }


        platypusView.addSubview(alligatorImageView)
        alligatorImageView.snp.makeConstraints { make in
            make.height.equalTo(32);
            make.width.equalTo(32);
            make.centerY.equalToSuperview()
            make.leading.equalTo(platypusView).offset(10);
        }

        platypusView.addSubview(octopusLabel)
        octopusLabel.snp.makeConstraints { make in
            make.height.equalTo(16);
            make.centerY.equalToSuperview();
            make.left.equalTo(alligatorImageView.snp.right).offset(6);
        }


        platypusView.addSubview(pigeonImageView)
        pigeonImageView.snp.makeConstraints { make in
            make.height.equalTo(16);
            make.width.equalTo(16);
            make.centerY.equalTo(platypusView);
            make.left.equalTo(octopusLabel.snp.right).offset(4);
        }


        platypusView.addSubview(redfoxLabel)
        redfoxLabel.snp.makeConstraints { make in
            make.height.equalTo(15);
            make.centerY.equalToSuperview()
            make.left.equalTo(pigeonImageView.snp.right).offset(4);
        }


//        platypusView.addSubview(blackpantherLabel)
//        blackpantherLabel.snp.makeConstraints { make in
//            make.height.equalTo(15);
//            make.width.equalTo(30);
//            make.centerY.equalTo(platypusView);
//            make.trailing.equalTo(-12)
//        }
//
//
//        platypusView.addSubview(seahorseButton)
//        seahorseButton.snp.makeConstraints { make in
//            make.height.equalTo(15);
//            make.width.equalTo(15);
//            make.centerY.equalToSuperview();
//            make.right.equalTo(blackpantherLabel.snp.left).offset(-5)
//        }
//
//
//        platypusView.addSubview(dragonflyView)
//        dragonflyView.snp.makeConstraints { make in
//            make.height.equalTo(18);
//            make.width.equalTo(1);
//            make.centerY.equalTo(platypusView);
//            make.right.equalTo(seahorseButton.snp.left).offset(-12)
//        }


        platypusView.addSubview(sheepButton)
        sheepButton.snp.makeConstraints { make in
            make.height.equalTo(30);
            make.width.equalTo(50);
            make.trailing.equalTo(-12)
            make.centerY.equalTo(platypusView);
        }


        myView.addSubview(impalaButton)
        impalaButton.snp.makeConstraints { make in
            make.height.equalTo(28);
            make.width.equalTo(30);
            make.trailing.bottom.equalToSuperview();
            //make.centerY.equalTo(None);
        }

        myView.addSubview(piranhaLabel)
        piranhaLabel.snp.makeConstraints { make in
            make.leading.equalTo(12);
            make.top.equalTo(platypusView.snp.bottom).offset(12)
            make.trailing.equalTo(-12);
            make.bottom.equalTo(-16);
        }


    }


    @objc func starfruitOnReplayactionAction() {
        
    }

    @objc func dragonfruitOnMoreactionAction() {
        
        if let delegate = self.delegate {
            delegate.didOnMoreAction()
        }
    }
}
